package com.hippo.client.controller.springdoc;

import com.hippo.client.controller.springdoc.model.BpmnXmlReq;
import com.hippo.client.controller.springdoc.model.JsonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName DemoController
 * @Description TODO springDoc演示例子
 * @Author tangxl
 * @create 2023-03-28 09:32
 **/
// Tag 注解, 给整个接口起了个名字 "流程定义", 描述是 "流程定义 API"
@Tag(name = "DemoController", description = "springDoc演示例子")
// ApiResponses 给每个接口提供一个默认的响应, 状态码是 200, 描述是 "接口请求成功"
@ApiResponses(@ApiResponse(responseCode = "200", description = "接口请求成功"))
@RestController("/springdoc")
public class DemoController {
    // Operation 注解设置了接口名称, 接口描述
    @Operation(summary = "上传 BPMN xml 字符串 并部署", description = "此接口处理的是 xml 字符串")
    @PostMapping("/upload-and-deploy/bpmn-xml-str")
    public JsonResult<?> uploadAndDeployBpmnXmlStr(@RequestBody BpmnXmlReq req) {
        return JsonResult.success(null);
    }

    @Operation(summary = "查询单个 bpmn xml 数据")
    @GetMapping("/bpmn-xml")
    public JsonResult<BpmnXmlReq> findBpmnXml(
            // Parameter 注解设置了请求参数的描述, 是否必填 以及示例
            @Parameter(description = "流程部署ID", required = true, example = "1234") String deployId,
            @Parameter(description = "流程资源名称", required = true, example = "xxx.bpmn") String resourceName) {
        return JsonResult.success(new BpmnXmlReq());
    }

    @Operation(summary = "上传 BPMN 文件并部署", description = "此接口处理的是文件流")
    @PostMapping(path = "/upload-and-deploy/bpmn-file", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public JsonResult<BpmnXmlReq> uploadAndDeployBpmnFile(
            @Parameter(description = "要上传的 BPMN 文件", required = true) MultipartFile file,
            @Parameter(description = "流程部署的名称", required = true) @RequestParam String deployName) {
        return JsonResult.success(new BpmnXmlReq());
    }

}
